package informed.interact;

import java.util.ArrayList;

import informed.samples.LinearRegressionSample;
import informed.samples.MatrixCellValue;
import informed.samples.Sample;
import informed.samples.VectorValueSample;
import informed.sgd.LinearRegression;
import informed.sgd.LatentTransformation;
import informed.sgd.RegularizedSVD;
import informed.sgd.SimpleMatrixFactorization;

public class Examples {

	/**
	 * @param args
	 */
	
	public static void main(String[] args) {
		String y = "/home/jccaicedo/workspace/StochasticGradientDescent/data/synthMatrix/y.txt";
		String x = "/home/jccaicedo/workspace/StochasticGradientDescent/data/synthMatrix/xT.txt";
		long start, end;
		int iter = 500;
		start = System.currentTimeMillis();
		ArrayList<Sample> samples = VectorValueSample.loadSparseSamples(x, y);
		System.out.println("Matrix file read. Samples = "+samples.size());
		LatentTransformation problem = new LatentTransformation(20, 6, 3);
		problem.run(samples, iter);
		System.out.println("Problem solved: " + problem.printSolution());
		end = System.currentTimeMillis();
		System.out.println("Elapsed time " + (end-start));
	}
	
	public static void regularizedSVD() {
		String x = "/home/jccaicedo/workspace/StochasticGradientDescent/data/synthMatrix/y.txt";
		ArrayList<Sample> samples = MatrixCellValue.loadSamples(x);
		System.out.println("Matrix file read. Samples = "+samples.size());
		RegularizedSVD problem = new RegularizedSVD(20, 6, 3);
		problem.run(samples, 500);
		System.out.println("Problem solved: " + problem.printSolution());
	}
	
	public static void matrixFactorization() {
		String x = "/home/jccaicedo/workspace/StochasticGradientDescent/data/synthMatrix/y.txt";
		ArrayList<Sample> samples = MatrixCellValue.loadSamples(x);
		System.out.println("Matrix file read. Samples="+samples.size());
		SimpleMatrixFactorization problem = new SimpleMatrixFactorization(20, 6, 3);
		problem.run(samples, 50);
		System.out.println("Problem solved: " + problem.printSolution());
	}
	
	public static void linearRegression(){
		String x = "/home/jccaicedo/workspace/StochasticGradientDescent/data/synthetic/xo.txt";
		String y = "/home/jccaicedo/workspace/StochasticGradientDescent/data/synthetic/yo.txt";
		ArrayList<Sample> samples = LinearRegressionSample.loadSamples(x,y);
		System.out.println("Files have been read. Records=" + samples.size());
		LinearRegression problem = new LinearRegression(0.00001);
		problem.run(samples, 1);
		System.out.println("Problem solved: " + problem.getSolution());
	}

}
